//
//  RoomDetailViewController.m
//  Charles
//
//  Created by Charles on 2018/5/13.
//  Copyright © 2018年 charles. All rights reserved.
//

#import "RoomDetailViewController.h"
#import "JPNavigationControllerKit.h"

@interface RoomDetailViewController ()<JPNavigationControllerDelegate>

@property (strong, nonatomic) UIImageView *coverImageView;

@property (strong, nonatomic) UIImageView *detailImageView;

@property (strong, nonatomic) NSLayoutConstraint *detailImageUpCons;

@end

@implementation RoomDetailViewController

- (instancetype)init {
    if (self = [super init]) {
        __weak typeof(self) weakSelf = self;
        self.fadeBlock = ^{
            __strong typeof(weakSelf) strongSelf = weakSelf;
            if (!strongSelf) return;
            
            [strongSelf.view layoutIfNeeded];
            
            strongSelf.detailImageUpCons.constant = 0;
            [UIView animateWithDuration:0.45 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                __strong typeof(weakSelf) strongSelf = weakSelf;
                if (!strongSelf) return;
                strongSelf.detailImageView.alpha = 1;
                CGRect fr = strongSelf.detailImageView.frame;
                fr.origin.y -= 20;
                strongSelf.detailImageView.frame = fr;
                [strongSelf.view layoutIfNeeded];
            }completion:nil];
        };
        [self class];
        [super class];
    }
    return self;
}

- (void)loadView {
    [super loadView];
    
    self.coverImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
    [self.view addSubview:self.coverImageView];
    self.coverImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.coverImageView.image = self.coverImage;

    
    self.detailImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.coverImageView.frame) + 20, SCREEN_WIDTH, 833/2)];
    [self.view addSubview:self.detailImageView];
    self.detailImageView.image = [UIImage imageNamed:@"AirbnbDetail"];
    self.detailImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.navigationController setNavigationBarHidden:YES];
    
    self.detailImageView.alpha = 0;
    self.detailImageUpCons.constant = 25;
    [self.view layoutIfNeeded];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(20, 40, 20, 20);
    [button addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    [button setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)backBtnClick:(id)sender {
    if (self.closeBlock) {
        self.closeBlock(self);
    }
    self.view.alpha = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)navigationControllerShouldStartPop:(JPNavigationController *)navigationController{
    [self backBtnClick:nil];
    return NO;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
